<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script type="text/javascript"
    src="https://api.map.baidu.com/api?v=1.0&type=webgl&ak=nCLyFZflw3HSiE56R8X1mflbv5ERasny"></script>

<body>
    <div id="container"></div>
</body>
<script>
    var map = new BMapGL.Map("container");
    var point = new BMapGL.Point(116.331398, 39.897445);
    map.centerAndZoom(point, 12);

    function myFun(result) {
        //   var cityName = result.name;
        //   map.setCenter(cityName);
        var cityName = result.name;
        var center = result.center;

        var geoc = new BMapGL.Geocoder();
        geoc.getLocation(center, function (rs) {
            var address = rs.address;
            console.log(address);
            sessionStorage.setItem('address',address)
            sessionStorage.setItem('getAddress',true)
            // alert("当前定位: " + address);

        });
    }
    var myCity = new BMapGL.LocalCity();
    // console.log(new BMapGL.LocalDistrict());
    myCity.get(myFun);

    // let point=new BMapGL.Point(115.502, 38.820);
    // var geolocation = new BMapGL.Geolocation();
    //     geolocation.getCurrentPosition(function (r) {
    //         if (this.getStatus() == BMAP_STATUS_SUCCESS) {
    //             // var mk = new BMapGL.Marker(r.point);
    //             // map.addOverlay(mk);
    //             // map.panTo(r.point);
    //             // point = r.point
    //             // alert('您的位置：' + r.address.city + ',' + r.address.district);
    //             console.log(r);
    //             console.log('您的位置：' + r.address.city + ',' + r.address.district+',');
    //             sessionStorage.setItem('city', r.address.city)
    //         }
    //         else {
    //             console.log('failed' + this.getStatus());
    //             alert('定位中');
    //         }
    //     }) 
</script>

</html>